# Figure of difficulties for political knowledge
pk.plot <- estimates %>% filter(model == "Political Knowledge (CR1)") %>% 
 bind_cols(politician = c("VP",
          "Senate Majority",
          "State Majority",
          "Governor",
          "Senator 1",
          "Senator 2",
          "Speaker of the House",
          "Secretary of Treasury",
          "Attorney General",
          "Majority Leader",
          "Sotomayor",
          "Rubio",
          "Alexandria Ocasio-Cortez",
          "Julian Castro")) %>%
 bind_cols(verbal = c(rep("Visual Guide", 1), rep("No Visual Guide", 5), rep("Visual Guide", 8))) %>%
 ggplot(aes(x = forcats::fct_reorder(politician, diff), y = diff, shape = verbal)) +
 coord_flip() +
 theme_ipsum_rc() +
 geom_pointrange(aes(ymin = diff - 1.96*se, ymax = diff + 1.96*se)) +
 theme(legend.position = "bottom") +
 geom_hline(yintercept = 0) +
 labs(x = "", y = "Difference in Item Difficulties", shape = "") +
 theme(strip.text.x = element_text(size = 14),
       text = element_text(size = 14),
       axis.text.x = element_text(size = 14),
       axis.text.y = element_text(size = 14)) 

# Figures of item-level DIF for Latino attachment and efficacy
dif.plot2 <- estimates %>% 
 filter(model == "Panethnic Identity (CR1)" | model == "Efficacy Beliefs (CR1)") %>% 
 mutate(sig = factor(2*as.numeric(diff - 1.96*se > 0) +  
                      1*as.numeric(diff + 1.96*se < 0), 
                     c(0,1,2), c("Not Significant", "Easier in English (p<.05)", "Easier in Spanish (p<.05)"))) %>% 
 group_by(item_name) %>%
 dplyr::mutate(cats = row_number()) %>% 
 ggplot(aes(x = forcats::fct_reorder(item_name, cats), y = cats, fill = sig, group = model)) +
 geom_tile(width=.75, height=.75, alpha = .5) + 
 geom_text(aes(label = round(diff, 2)), size = 4) +
 coord_flip() + 
 theme_ipsum_rc() + 
 scale_fill_manual(values=c("#F3F3F3", "#999999", "#000000")) + 
 theme(legend.position = "bottom") + labs(y = "Response category (k/k+1)") + 
 theme(panel.grid.minor = element_blank(), panel.grid.major = element_blank())  +
 facet_wrap(. ~ forcats::fct_reorder(model, study), scales = "free") +
 theme(axis.text.x = element_blank()) +
 labs(x = "", fill = "")
